<?php
    abstract class BaseController {
    	static protected $db_link;
		static public $config;
		
    	static public function ProcessRequest($request) {}

		static protected function ProcessQuery($query) {
			if (self::$db_link -> multi_query($query)) {
				do {
					if ($result = self::$db_link -> store_result())
						$result -> free();
				} while(self::$db_link->next_result());
				echo json_encode((object) array("success" => true));
			} else
				echo(json_encode((object) array("success" => false, "error" => self::$db_link -> error)));
		}
		
		static protected function SQL_close() {
			self::$db_link -> close();
			self::$db_link = null;
		}
		
		static protected function SQL_connect() {
			self::$db_link = new mysqli(self::$config -> db_host, self::$config -> db_user, self::$config -> db_pass, self::$config -> db_name);
			if (mysqli_connect_errno()) {
				echo "Не могу соединиться с базой данных";
				exit();
			}
			self::$db_link->query("SET NAMES utf8;");
		}		
    }
?>